package com.uhylab.uhuvinetest.fragment;

import android.content.Intent;
import android.os.Handler;
import android.os.Message;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.uhylab.uhuvinetest.R;
import com.uhylab.uhuvinetest.base.UHBaseFragment;
import com.uhylab.uhuvinetest.camera.CaptureActivity;
import com.uhylab.uhuvinetest.view.VelocimeterView;

/**
 * Created by xyb on 15/12/4 at UHylab
 *
 * @version 1.0
 */
public class UHPhotoFragment extends UHBaseFragment implements View.OnClickListener {
    //private CircleBar circleBar;
    int maxStepnumber;
   // private CircleBar.BarAnimation barAnimation;
//    private TextView textView;
    private boolean first;

    private VelocimeterView mVelocimeterView;


    @Override
    public void initData() {
        maxStepnumber = 1;
//        circleBar.setMaxstepnumber(maxStepnumber);
//        circleBar.setOnClickListener(new View.OnClickListener() {
//
//            @Override
//            public void onClick(View v) {
//                circleBar.setEnabled(false);
//                /**
//                 * 点击设置步数
//                 */
//                circleBar.update(maxStepnumber,
//                        maxStepnumber * 1000);
//                barAnimation = circleBar.getBarAnimation();
//                barAnimation.setAnimationListener(new Animation.AnimationListener() {
//                    @Override
//                    public void onAnimationStart(Animation animation) {
//                        first = false;
////                        textView.setText("检测已经开始,倒计时完成后会进行图像获取,请您稍候");
////                        textView.setVisibility(View.VISIBLE);
//                    }
//
//                    @Override
//                    public void onAnimationEnd(Animation animation) {
//                        Intent intent = new Intent();
//                        intent.setClass(getContext(), CaptureActivity.class);
//                        startActivity(intent);
//                    }
//
//                    @Override
//                    public void onAnimationRepeat(Animation animation) {
//
//                    }
//                });
//            }
//        });
    }

    @Override
    protected void initDestrory() {
        handler.removeMessages(0);
    }

    @Override
    protected void initView() {
//        circleBar = (CircleBar) view.findViewById(R.id.circle);
        first = true;
//        textView = (TextView) view.findViewById(R.id.text);
        mVelocimeterView = (VelocimeterView) view.findViewById(R.id.velocimeter);
        mVelocimeterView.setOnClickListener(this);
        mVelocimeterView.setValue(0);
        handler.sendEmptyMessageDelayed(0,1000);
    }

    @Override
    protected View inflaterView(LayoutInflater inflater, ViewGroup container) {
        view = inflater.inflate(R.layout.fragment_photo, null);


        return view;
    }

    @Override
    public void onResume() {
        super.onResume();
        if (first) {

        } else {
//            circleBar.Restart();
//            circleBar.postInvalidate();
//            circleBar.setEnabled(true);
//            textView.setVisibility(View.GONE);
        }
    }

    @Override
    public void onPause() {
        super.onPause();
//        circleBar.onPause();

    }

    private Handler handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            float value = mVelocimeterView.getValue();
            value += 1;
            handler.sendEmptyMessageDelayed(0,1000);
            if (value > mVelocimeterView.getMax()) {
                value = mVelocimeterView.getMax();
                handler.removeMessages(0);
                Intent intent = new Intent();
                intent.setClass(mActivity, CaptureActivity.class);
//                getActivity().setContentView(R.layout.fragment_home);
                startActivity(intent);

            }
            mVelocimeterView.setValue(value);
        }
    };


    @Override
    public void onClick(View v) {
        Intent intent = new Intent();
        intent.setClass(mActivity, CaptureActivity.class);
//                getActivity().setContentView(R.layout.fragment_home);
        startActivity(intent);
    }
}
